//tab切换 二级菜单
;
(function() {
    $.fn.extend({
        tabChange() {
            let self = this;
            $(this).find(".b-red>a").mouseenter(function() {
                var $index = $(this).parent().index()
                self.find(".b-red").eq($index).children().eq(1).addClass("hover")
            }).mouseleave(function() {
                var $index = $(this).parent().index()
                self.find(".b-red").eq($index).children().eq(1).removeClass("hover")

            })
        }
    })
})()
$(function() {
    $(".nav-ul").tabChange()
})

//轮播图
;
(function() {
    class GapSwiper {
        constructor(el) {
            this.el = el
                // console.log(this.el); //#bannerWrap
            this.divList = this.el.find(".banner").children(); //imgs
            this.liList = this.el.find(".banner-ol").children(); //lis
            this.divIndex = 0
            this.mouseHandler()
            this.autoPlay()
            this.mouseClick()
        }
        autoPlay() {
            this.timer = setInterval(() => {
                this.divIndex++;
                this.auto();
            }, 4000)
        }
        auto() {
            if (this.divIndex > 6) {
                this.divIndex = 0
            }
            //图片的轮播
            this.divList.eq(this.divIndex).stop().animate({ opacity: "1" }).siblings().stop().animate({ opacity: 0 })
                //li的轮播
            this.liList.eq(this.divIndex).addClass("active").siblings().removeClass("active")
        }
        mouseHandler() {
            this.el.mouseenter(() => {
                clearInterval(this.timer);
            }).mouseleave(() => {
                // this.autoPlay();
                this.autoPlay()
            })
        }
        mouseClick() {
            this.el.find(".index-b-left").click(() => {
                this.divIndex--
                    if (this.divIndex < 0) {
                        this.divIndex = 6
                    }
                this.auto()
            })
            this.el.find(".index-b-right").click(() => {
                this.divIndex++
                    if (this.divIndex > 6) {
                        this.divIndex = 0
                    }
                this.auto()
            })

            this.liList.each((index, item) => {
                // console.log(item);
                $(item).click(() => {
                    this.divIndex = index
                    this.divList.eq(index).stop().animate({ opacity: "1" }).siblings().stop().animate({ opacity: 0 })
                        //li的轮播
                    this.liList.eq(index).addClass("active").siblings().removeClass("active")
                })
            })
        }

    }


    $.fn.extend({
        swiperAuto() {
            new GapSwiper(this);
        }
    })
})();

$(function() {
    $("#bannerWrap").swiperAuto()
})


//退出
$(function() {
    var login = JSON.parse(sessionStorage.getItem("userInfo"))
    if (login == null || login == undefined) {
        $("#tuichu").css({
            display: "none"
        })
    } else {
        $("#tuichu").css({
            display: "block"
        })
    }
    $("#tuichu").click(function() {
        sessionStorage.clear()
        location.reload()

    })
})

$(function() {
    var user = JSON.parse(sessionStorage.getItem("userInfo"));

    if (user != null || undefined) {
        var strHtml = `欢迎会员${user.name}`
        $(".login").children().eq(0).text(strHtml);
        $(".login").children().eq(0).css({
            color: "red",
            fontSize: "14px",
            lineHeight: "30px",
            display: "inline-block"
        })
    }
})